<template>
	<view class="content">

		<skeleton class="topw" :row="3" :avatar="'left'" :avatarShape="'round'" :avatarSize="'150rpx'" :loading="loading">
			<view class="top" ref="top">
				<view class="nav">
					<text class="icon cuIcon-back_android" @click="back"></text>
					<text>歌单</text>
					<text></text>
				</view>
				<view class="main">
					<image lazy-load @load="imgLoad" :src="info.img" class="fadeShow" :class="loaded?'showImg':'hiddenImg' "></image>
					<image mode="aspectFit" src="../../static/images/loading.png" v-show="!loaded"></image>
					<view>
						<view style="font-size: 32rpx;">{{info.name}}</view>
						<view>简介：{{info.desc}}</view>
					</view>
				</view>
				<image class="bg fadeShow" :src="info.img" :class="loaded?'showImg':'hiddenImg'"></image>
			</view>
		</skeleton>

		<skeleton class="songList" :row="10" :loading="loading" :rowHeight="'50rpx'">
			<view class="songList">
				<block v-for="(item,index) in list">
					<view class="song" @click="play(item,index)">
						<image :src="item.img"></image>
						<view class="song-item">
							<text class="name">{{item.song}}</text>
							<text class="desc">{{item.singer}}</text>
						</view>
						<image class="more" src="../../static/images/more.png"></image>
					</view>
				</block>
				<view class="blank" v-if="empty">暂无喜欢的歌曲，快去添加吧！</view>
			</view>
		</skeleton>

		<!-- 底部播放器 -->
		<BottomBar></BottomBar>
	</view>
</template>

<script>
	import skeleton from '@/components/xinyi-skeleton/skeleton.vue'
	import BottomBar from '../../components/BottomBar/index.vue'
	import {
		get
	} from '../../utils/http.js'
	export default {
		data() {
			return {
				listID: '',
				list: [],
				info: '',
				empty: '',
				loading: true,
				loaded: false
			}
		},
		components: {
			BottomBar,
			skeleton
		},
		methods: {
			imgLoad(e) {
				this.loaded = true
			},
			async getSongList(id) {
				// 请求过id的信息存储到全局进行缓存
				if (getApp().globalData['info' + id]) {
					return this.info = getApp().globalData['info' + id]
				}
				await get('/songlist/' + id).then(res => {
					this.info = res
					getApp().globalData['info' + id] = res
				})
			},
			async getSongs(id) {
				if (getApp().globalData['list' + id]) {
					this.list = getApp().globalData['list' + id]
					return this.loading = false
				}
				await get('/song/list/' + id).then(res => {
					this.list = res
					getApp().globalData['list' + id] = res
					this.loading = false
				})
			},
			getLikeList() {
				let list = uni.getStorageSync('like_songList')
				if (!list[0]) {
					this.empty = true
					return
				}
				this.list = list.reverse()
			},
			getRecentList() {
				let list = uni.getStorageSync('recent_list')
				this.list = list.reverse()
			},
			play(item, i) {
				this.$player.src = item.play_url
				this.$store.commit('play')
				uni.setStorageSync('last_play', item)
				this.$store.commit('setInPlay', item)
				this.$store.commit('set_current_song_no', i)
				this.$store.commit('SET_SONGLIST', this.list)
			},
			//关闭当前组件
			back() {
				uni.navigateBack()
			}
		},
		async created() {
			uni.showLoading()
			if (this.listID == 'like') {
				this.getLikeList()
				this.info = {
					name: '我喜欢的音乐',
					desc: 'like',
					img: this.empty ? '/static/images/music.jpg' : this.list[0].img
				}
				uni.hideLoading()
				this.loading = false
				return
			}
			await this.getSongList(this.listID)
			await this.getSongs(this.listID)
			uni.hideLoading()
		},
		onLoad(options) {
			this.listID = options.listID
		},
		mounted() {
			// this.$refs.top.$el.style.backgroundImage = '../../static/images/swiper3.jpg'
		},
		onBackPress() {

		}
	}
</script>

<style lang="scss" scoped>
	.content {
		// height: 100vh;
		width: 100vw;
		display: flex;
		flex-direction: column;
		overflow-y: auto !important;
	}

	.topw {
		z-index: 1;
	}

	.top {
		padding: 10rpx 0 30rpx 0;
		z-index: 1;
		// height: 30%;
		// border: 1rpx solid;
	}

	.bg {
		position: absolute;
		top: 0;
		height: 300rpx;
		width: 100%;
		z-index: -1;
		-webkit-filter: blur(70rpx);
		filter: blur(70rpx);
		transform: scale(1.2);
		opacity: 0.8;
		-webkit-opacity: 0.8;
	}

	.nav {
		position: relative;
		top: 0;
		height: 80rpx;
		display: flex;
		font-size: 32rpx;
		color: #FFFFFF;
		align-items: center;
		justify-content: space-between;
	}

	.cuIcon-back_android {
		font-size: 60rpx !important;
	}

	.main {
		margin-top: 10rpx;
		display: flex;
		padding: 20rpx;

		image {
			width: 200rpx;
			height: 200rpx;
		}

		view {
			margin-left: 30rpx;
			display: flex;
			flex-direction: column;
			justify-content: space-around;

			view {
				font-size: 28rpx;
				width: 450rpx;
				text-overflow: ellipsis;
				overflow: hidden;
				display: -webkit-box;
				-webkit-line-clamp: 2;
				line-clamp: 2;
				-webkit-box-orient: vertical;
				color: #FFFFFF;
				opacity: 0.9;
			}
		}
	}


	.songList {
		width: 100%;
		margin-bottom: 90rpx !important;
		display: flex;
		flex-direction: column;
	}

	.song {
		padding: 20rpx 20rpx 20rpx 40rpx;
		width: 100%;
		display: flex;
		align-items: center;
		background: #FFFFFF;
	}

	.song:active {
		background-color: #F6F6F6;
	}

	.song-item {
		height: 100rpx;
		display: flex;
		flex-direction: column;
		justify-content: space-around;
		margin-left: 20rpx;
	}

	.song image {
		border-radius: 5%;
		width: 100rpx;
		height: 100rpx;
	}

	.name {
		font-size: 32rpx;
		width: 450rpx;
		display: block;
		white-space: nowrap;
		text-overflow: ellipsis;
		overflow: hidden;
		cursor: pointer;
	}

	.desc {
		font-size: 24rpx;
		color: #808080;
		display: block;
		white-space: nowrap;
		text-overflow: ellipsis;
		overflow: hidden;
		width: 450rpx;
		cursor: pointer;
	}

	.more {
		height: 60rpx !important;
		width: 60rpx !important;
		margin-left: 60rpx;
	}

	.blank {
		text-align: center;
	}

	.sth {
		height: 100%;
		width: 100%;
		background-color: #F2F3F5;
	}
</style>
